/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.txweb.result;

import com.jspx.txweb.ActionInvocation;
import com.jspx.txweb.Action;
import com.jspx.txweb.dispatcher.Dispatcher;
import com.jspx.txweb.support.ActionSupport;
import com.jspx.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by IntelliJ IDEA.
 * User:chenYuan (mail:39793751@qq.com)
 * Date: 2006-12-27
 * Time: 15:42:39
 * 页面跳转
 */
public class RedirectResult extends ResultSupport {
    private static final Logger log = LoggerFactory.getLogger(RedirectResult.class);

    public void execute(ActionInvocation actionInvocation) throws Exception {
        Action action = actionInvocation.getActionProxy().getAction();
        HttpServletResponse response = action.getResponse();
        response.setContentType("text/html; charset=" + Dispatcher.getEncode());
        if (response.isCommitted())
        {
            log.error("redirect response.isCommitted():" + response.isCommitted());
            return;
        }
        String url = null;
        try {
          url = getConfigLocationUrl(actionInvocation);
          if (!StringUtil.isNULL(url)) {
              response.sendRedirect(url);
              action.setActionResult(ActionSupport.NONE);
          }
        } catch (Exception e) {
            log.error(actionInvocation.getActionName()+ "检查跳转配置是否正确,check redirect config action is:" + url,e);
        }
    }
}